package com.weiyuwqj.admin.controller.admin.financial;

import com.weiyuwqj.admin.controller.base.BaseController;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.convert.AccountRechargeAddtimeConvert;
import com.weiyuwqj.api.model.convert.ModelConvert;
import com.weiyuwqj.api.model.vo.ManageAmountDetailsVO;
import com.weiyuwqj.api.service.SysAmountOperateService;
import com.weiyuwqj.api.util.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/25.
 */
@Controller
public class ManageAmountDetailsController extends BaseController{

    @Autowired
    private SysAmountOperateService operateService;

    @ResponseBody
    @RequestMapping(value ="/financial/amountDetails/list",method = RequestMethod.POST)
    public Object getAmountDetailsList(Paginator p,ManageAmountDetailsVO detailsVO){
        return operateService.getAmountDetailsList(p,detailsVO);
    }

    @ResponseBody
    @RequestMapping(value = "/financial/amountDetails/excel",method = RequestMethod.POST)
    public Object getAmountDetailsList(HttpServletRequest request,ManageAmountDetailsVO detailsVO){
        String[] cArray={"ID","订单号","类型","名称","对应标的","操作时间","订单金额"};
        String[] eArray={"Id","OrderNo","OperateType","AssetName","ItemName","Addtime","OperateAmount"};
        ModelConvert[] converts={null,null,null,null,null,new AccountRechargeAddtimeConvert(),null};
        List<String> cList= Arrays.asList(cArray);
        List<String> eList=Arrays.asList(eArray);
        List<ModelConvert> convertList=Arrays.asList(converts);
        List<ManageAmountDetailsVO> contentList = operateService.getAmountDetailsList(detailsVO);
        String serverDir=request.getServletContext().getRealPath("/")+"admin/export/";
        String excelFilePath= ExcelUtils.export("资金日志", cList, eList, convertList, contentList, serverDir);
        HashMap ret= Message.OK;
        ret.put("file","export/"+excelFilePath);
        return ret;
    }

    @ResponseBody
    @RequestMapping(value ="/financial/amountDetails/stat",method = RequestMethod.POST)
    public Object statAmountDetails(ManageAmountDetailsVO detailsVO){
        return operateService.statAmountDetails(detailsVO);
    }
}
